//
//  EGShoppingCartController.m
//  Orchard
//
//  Created by ios001 on 16/8/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "EGShoppingCartController.h"
#import "EGShoppingCartView.h"
#import "EGShoppingCartParticularView.h"
#import "EGPaymentViewController.h"

@interface EGShoppingCartController ()

@property (nonatomic,strong) EGShoppingCartView *shopCartView;

@property (nonatomic,strong) NSArray   *goodsArr;

@property (nonatomic,strong) EGShoppingCartParticularView *particularView;

@property (nonatomic,strong) UIView    *bottomView;

@property (nonatomic,strong) UIButton  *buyBtn;
@end

@implementation EGShoppingCartController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
    [self setupNav];
    [self setLayout];
    self.navigationItem.title = @"购物车";
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissVc) name:@"dismiss" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenVc) name:@"hiddenVc" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushVc) name:@"pushVc" object:nil];
    
}

- (void)hiddenVc{
    self.particularView.hidden = YES;
    self.shopCartView.hidden = NO;
}

- (void)pushVc{
    [self.navigationController pushViewController:[EGPaymentViewController new] animated:YES];
}

- (void)setupUI{
    [self.view addSubview:self.shopCartView];
    [self.view addSubview:self.particularView];
//    [self.bottomView addSubview:self.buyBtn];
    [self.shopCartView makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.trailing.leading.equalTo(self.view);
    }];
//    [self.view addSubview:self.particularView];
    if (self.goodsArr.count == 0) {
        self.particularView.hidden = YES;
    }else{
//        [self.view addSubview:self.particularView];
        self.shopCartView.hidden = YES;
        
    }
    
//    [self.view addSubview:self.bottomView];
    
}

- (void)setLayout{
//    [self.bottomView makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.trailing.leading.equalTo(self.view);
//        make.height.offset(49);
//    }];
//    
//    [self.buyBtn makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.trailing.equalTo(self.bottomView);
//        make.width.equalTo(100);
//    }];
}

- (void)setupNav{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"v2_goback"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(didClickButotn)];
}

- (void)didClickButotn{
    [self dismissVc];
}

- (void)dismissVc{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 懒加载控件
- (EGShoppingCartView *)shopCartView{
    if (_shopCartView == nil) {
        _shopCartView = [[EGShoppingCartView alloc] init];
    }
    return _shopCartView;
}

- (NSArray *)goodsArr{
    if (_goodsArr == nil) {
//                _goodsArr = [NSArray array];
        _goodsArr = [NSArray arrayWithObject:@10];
    }
    return _goodsArr;
}

- (EGShoppingCartParticularView *)particularView{
    if (_particularView == nil) {
        _particularView = [[EGShoppingCartParticularView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    return _particularView;
}

- (UIView *)bottomView{
    if (_bottomView == nil) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

- (UIButton *)buyBtn{
    if (_buyBtn == nil) {
        _buyBtn = [[UIButton alloc] init];
        [_buyBtn setTitle:@"选好啦" forState:UIControlStateNormal];
        _buyBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _buyBtn.backgroundColor = ThemeColor;
        [_buyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _buyBtn;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
